package com.matete.agentmanage.common.utils;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;

public class JavaTranslate {

	/**
	 * Date 转换为 Datetime
	 */
	
	public Timestamp DateToDatetime(Date date){
		return new Timestamp(date.getTime());
	}
	
	/**
	 * String 转换为 Date
	 */
	
	public Date StringToDate(String str){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");   
		  
		Date date = null; //初始化date   
		  
		try {   
		  
		date = sdf.parse(str); //Mon Jan 14 00:00:00 CST 2013   
		  
		} catch (Exception e) {   
		  
		e.printStackTrace();   
		  
		}
		return date;
	}
	
	
	/**
	 * String 转换为 Date
	 */
	
	public Date StringToTimestamp(String str){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");   
		  
		Date date = null; //初始化date   
		  
		try {   
		  
		date = sdf.parse(str); //Mon Jan 14 00:00:00 CST 2013   
		  
		} catch (Exception e) {   
		  
		e.printStackTrace();   
		  
		}
		return date;
	}
	
	/**
	 *  String 转换为 java.sql.Date
	 */
	public java.sql.Date StringToSQLDate(String str){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");   
		  
		java.sql.Date sdate = null; //初始化   
		  
		try {   
		  
			java.util.Date udate = sdf.parse(str);   
		  
			sdate = new java.sql.Date(udate.getTime()); //2013-01-14   
		  
		} catch (Exception e) {   
		  
			e.printStackTrace();   
		  
		}
		return sdate;
	}
	
	/**
	 * String 转换为 Datetime
	 */
	public Timestamp StringToDatetime(String str){
		return DateToDatetime(StringToTimestamp(str));
	}
}
